package org.codert.domain;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.lang.Nullable;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * @author 谭景玉
 */
public interface OrderRepository extends CrudRepository<Order, Order.OrderId> {

    @Override
    Optional<Order> findById(Order.OrderId orderId);

    Order findByOrderName(@Nullable String orderName);

    Stream<Order> findAllByOrderName(String orderName);

//    @Query("select o from #{#entityName} o where o.orderName like %?#{escape([0])}% escape ?#{escapeCharacter()}")
    @Query("select o from #{#entityName} o where o.orderName like %?#{escape([0])}%")
    List<Order> findAllByOn(String orderName);

}
